#include "queue_base_array.h"

//创建队列
QUEUE *queue_create(int cap){
	QUEUE *queue = malloc(sizeof(QUEUE));
	queue -> arr = malloc(cap * sizeof(int));
	queue -> cap = cap;
	queue -> front = 0;
	queue -> back = 0;
	queue -> size = 0;
	return queue;
	}
//销毁队列
void queue_destroy(QUEUE *queue){
		free(queue -> arr);
		free(queue);
	}
//入队函数
void queue_push(QUEUE *queue,int data){
	queue -> arr[queue -> back] = data;
	queue -> back++;
	if(queue -> back == queue -> cap){
		//到达数组尾部，环绕回去
		queue -> back = 0;	
		}
	queue -> size++;//存储队列中有效队列元素个数
	}
//出队函数
int queue_pop(QUEUE *queue){
	int data =  queue -> arr[queue -> front++];
	if(queue -> front == queue -> cap){
		queue -> front = 0;
		}
	queue -> size--;
	return data;
	}
//判空 为空返回1 否则返回0
int queue_empty(QUEUE *queue){
	if(queue -> size ){
		return 0;
		}else{
		return 1;
			}
	}
//判满 满返回1 否则返回0
int queue_full(QUEUE *queue){
	if(queue -> size == queue -> cap){
		return 1;
		}
		return 0;
	}
